package com.sky.rabbit.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitTopicConfig {

    @Bean
    public Queue topicQueue(){
        return new Queue("topic.sky");
    }

    @Bean
    public TopicExchange skyExchange(){
        return new TopicExchange("skyExchange");
    }

    @Bean
    public Binding bindingSkyExchange(Queue topicQueue, TopicExchange skyExchange){
        // with 中设置参数为通配符方式，可以用* 也可以用 #
        // * 表示陪陪一个词 比如 topic.sky.order  如果是 topic.sky.order.detail 用* 就无法匹配，需要用#
        // # 表示可以匹配一个或者多个。比如topic.sky.order能用#匹配 topic.sky.order.detail 也可以匹配
        return BindingBuilder.bind(topicQueue).to(skyExchange).with("topic.sky.*");
    }

    @Bean
    public Queue skyTopicQueue(){
        return new Queue("sky.topic");
    }

    @Bean
    public TopicExchange skyTopicExchange(){
        return new TopicExchange("skyTopicExchange");
    }

    @Bean
    public Binding bindingDirectExchange(Queue skyTopicQueue, TopicExchange skyTopicExchange){
        return BindingBuilder.bind(skyTopicQueue).to(skyTopicExchange).with("sky.topic.#");
    }

    @Bean
    public Queue fanoutQueue(){
        return new Queue("fanout.sky");
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    public Binding bindingFanout(Queue fanoutQueue, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
    }

    @Bean
    public Queue skyDirectQueue(){
        return new Queue("direct.sky");
    }

    @Bean
    public DirectExchange skyDirectExchange(){
        return new DirectExchange("skyDirectExchange");
    }

    @Bean
    public Binding bindingSkyDirectExchange(Queue skyDirectQueue, DirectExchange skyDirectExchange){
        return BindingBuilder.bind(skyDirectQueue).to(skyDirectExchange).with("direct.sky.hct");
    }
}

